﻿// use_2_fjcx.cpp: 实现文件
//

#include "pch.h"
#include "HoManSys1.h"
#include "use_2_fjcx.h"
#include "afxdialogex.h"
#include "ADOconnection.h"

// use_2_fjcx 对话框
ADOconnection con2;
ADOconnection con3;
IMPLEMENT_DYNAMIC(use_2_fjcx, CDialogEx)

use_2_fjcx::use_2_fjcx(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_fjcx, pParent)
	, m_money(_T(""))
{

}

use_2_fjcx::~use_2_fjcx()
{
}

void use_2_fjcx::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_comb);
	DDX_Control(pDX, IDC_LIST3, m_list);
	DDX_Text(pDX, IDC_EDIT1, m_money);
}


BEGIN_MESSAGE_MAP(use_2_fjcx, CDialogEx)
	ON_CBN_SELCHANGE(IDC_COMBO1, &use_2_fjcx::OnCbnSelchangeCombo1)
END_MESSAGE_MAP()


// use_2_fjcx 消息处理程序


BOOL use_2_fjcx::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	con2.DBConnection();//数据库链接
		//执行查询，创建结果集
	m_pStr.CreateInstance(__uuidof(Recordset));
	CString str = _T("select typename from type");
	m_pStr->Open(_bstr_t(str), con2.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockBatchOptimistic, adCmdText);

	while (m_pStr->adoEOF == VARIANT_FALSE)
	{
		sValue = m_pStr->GetCollect("typename");
		str_s = (char*)_bstr_t(sValue);
		m_comb.AddString(str_s);
		m_pStr->MoveNext();

	}

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void use_2_fjcx::OnCbnSelchangeCombo1()
{
	// TODO: 在此添加控件通知处理程序代码
	con2.DBConnection();
	m_list.ResetContent();
	int posIndex = m_comb.GetCurSel();
	CString str_s;
	m_comb.GetLBText(posIndex, str_s);

	CString str = _T("select * from type,room where type.typeID=room.typeID and room.state=0 and type.typename='" + str_s + "'");
	m_pN.CreateInstance(__uuidof(Recordset));
	m_pN->Open(_bstr_t(str), con2.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);

	while (m_pN->adoEOF == VARIANT_FALSE)
	{
		

		roomValue = m_pN->GetCollect("roomID");
		str_room = (char*)_bstr_t(roomValue);
		m_list.AddString(str_room);
		m_pN->MoveNext();
	}
	m_pM.CreateInstance(__uuidof(Recordset));
	m_pM->Open(_bstr_t(str), con2.m_pCon.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	moneyValue = m_pM->GetCollect("money");
	str_money = (char*)_bstr_t(moneyValue);
	m_money = str_money;
	UpdateData(false);
	

}
